package com.xthink.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xthink.common.pojo.cards.CardsIMEI;
import com.xthink.common.result.AjaxResult;
import com.xthink.common.vo.cards.IMEIHistoryVo;
import com.xthink.web.mapper.CardsIMEIMapper;
import com.xthink.web.service.CardsIMEIService;
import com.xthink.web.service.CardsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardsIMEIServiceImpl extends ServiceImpl<CardsIMEIMapper, CardsIMEI> implements CardsIMEIService {

    @Autowired
    private CardsIMEIMapper cardsIMEIMapper;

    //获取IMEI历史记录
    @Override
    public AjaxResult getIMEIHistory(IMEIHistoryVo imeiHistoryVo) {
        Integer cardId = imeiHistoryVo.getCardId();

        LambdaQueryWrapper<CardsIMEI> wrapper = new LambdaQueryWrapper<>();

        Page<CardsIMEI> page = new Page<>(imeiHistoryVo.getPage(), imeiHistoryVo.getSize());

        wrapper.eq(CardsIMEI::getCardId,cardId);
        Page<CardsIMEI> page1 = cardsIMEIMapper.selectPage(page, wrapper);
        List<CardsIMEI> records = page1.getRecords();
        if (records.size()==0){
            return AjaxResult.error("暂未搜索到此卡片历史IMEI");
        }
        return AjaxResult.success(records);

    }
}
